package com.example.informationEntry.service.impl;

import com.example.informationEntry.entity.NaEmergencyContactInformation;
import com.example.informationEntry.dao.NaEmergencyContactInformationDao;
import com.example.informationEntry.service.NaEmergencyContactInformationService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 紧急联系人信息(NaEmergencyContactInformation)表服务实现类
 *
 * @author makejava
 * @since 2019-04-17 15:16:58
 */
@Service("naEmergencyContactInformationService")
public class NaEmergencyContactInformationServiceImpl implements NaEmergencyContactInformationService {
    @Resource
    private NaEmergencyContactInformationDao naEmergencyContactInformationDao;

    /**
     * 通过ID查询单条数据
     *
     * @param emergencyContactNumber 主键
     * @return 实例对象
     */
    @Override
    public NaEmergencyContactInformation queryById(String emergencyContactNumber) {
        return this.naEmergencyContactInformationDao.queryById(emergencyContactNumber);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<NaEmergencyContactInformation> queryAllByLimit(int offset, int limit) {
        return this.naEmergencyContactInformationDao.queryAllByLimit(offset, limit);
    }
    
    /**
     * 条件查询多条数据
     *
     * @param naEmergencyContactInformation 实例对象
     * @return 对象列表
     */
    @Override
    public List<NaEmergencyContactInformation> queryAll(NaEmergencyContactInformation naEmergencyContactInformation) {
        return this.naEmergencyContactInformationDao.queryAll(naEmergencyContactInformation);
    }

    /**
     * 新增数据
     *
     * @param naEmergencyContactInformation 实例对象
     * @return 实例对象
     */
    @Override
    public NaEmergencyContactInformation insert(NaEmergencyContactInformation naEmergencyContactInformation) {
        this.naEmergencyContactInformationDao.insert(naEmergencyContactInformation);
        return naEmergencyContactInformation;
    }

    /**
     * 修改数据
     *
     * @param naEmergencyContactInformation 实例对象
     * @return 实例对象
     */
    @Override
    public NaEmergencyContactInformation update(NaEmergencyContactInformation naEmergencyContactInformation) {
        this.naEmergencyContactInformationDao.update(naEmergencyContactInformation);
        return this.queryById(naEmergencyContactInformation.getEmergencyContactNumber());
    }

    /**
     * 通过主键删除数据
     *
     * @param emergencyContactNumber 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String emergencyContactNumber) {
        return this.naEmergencyContactInformationDao.deleteById(emergencyContactNumber) > 0;
    }

    @Override
    public Map<String, Map<String ,String>> queryNumberToName(){
        Map<String, Map<String ,String>> resultMap = new HashMap<>();
        List<NaEmergencyContactInformation> resultList = this.queryAll(new NaEmergencyContactInformation());
        for (NaEmergencyContactInformation information : resultList) {
            Map<String ,String> map = new HashMap<>();
            map.put("emergencyContactName",information.getEmergencyContactName());
            map.put("emergencyContactRelationshipNumber",information.getEmergencyContactRelationshipNumber());
            map.put("emergencyContactPhone",information.getEmergencyContactPhone());
            resultMap.put(information.getEmergencyContactNumber(),map);
        }
        return resultMap;
    }
}